<template>
	<view class="u-p-30">
		<view class="u-flex" style="border-bottom: 1rpx solid #E1E1E1FF;">
			<view class="u-m-r-20">兑换抽奖次数:</view>
			<u-input v-model="value" :type="type" placeholder="输入兑换次数" />
		</view>
		<view class="u-flex u-row-between u-m-t-30">
			<view class="u-flex">
				<view class="cl_898989FF u-font-28 u-p-6">可用积分</view>
				<u-image src="https://www.sqkjkj.vip/wxImg/common/bigturntable/money.png" mode="aspectFill" width="28rpx" height='28rpx'>
				</u-image>
				<view class="cl_FF5502FF u-p-6">{{userinfo.score}}</view>
			</view>
			<view class="u-flex">
				<view class="cl_898989FF u-font-28 u-p-6">所需积分</view>
				<u-image src="https://www.sqkjkj.vip/wxImg/common/bigturntable/money.png" mode="aspectFill" width="28rpx" height='28rpx'>
				</u-image>
				<view class="cl_FF5502FF u-p-6">{{numAll}}</view>
			</view>
		</view>
		<view class=" u-auto u-font-26 u-m-t-30 u-p-20 u-b-r-16" style="background-color: #FFE4B7FF;">
			<view class="cl_FF5502FF  u-p-6 u-weight">
				1.积分可兑换抽奖次数，中奖商品
			</view>
			<view class="cl_FF5502FF  u-p-6 u-weight">
				2.中奖商品3-7天内发出
			</view>
			<view class="cl_FF5502FF u-p-6 u-weight">
				3.积分可兑换抽奖次数发出中奖
			</view>
		</view>
		<view class=" u-m-t-150 u-w-640 u-h-98 bl2C_3F u-l-h-98 u-text-center u-b-r-20 u-auto"
			style="letter-spacing: 4rpx;color: #ffffff;" @click="change">立即兑换</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				value: '',
				type: 'number',
				userinfo: '',
				num: '',
				score_trade_luck_num:0
			}
		},
		onLoad(obj) {
			this.num = obj.num
			console.log(obj);
			// this.massage()
		},
		onShow() {
			this.massage()
		},
		computed:{
			numAll(){
				let num=this.value*this.score_trade_luck_num
				return num
			}
		},
		methods: {
			massage() {
				this.$api.get_my_massage({}, res => {
					console.log(res);
					if (res.data.code == 1) {
						this.userinfo = res.data.data.data
						this.score_trade_luck_num=Number(this.userinfo.score_trade_luck_num)
						uni.setStorageSync("userinfo", this.userinfo)
					}
				})
			},
			change() {
				if (this.value.trim() == '') {
					uni.showToast({
						icon: 'none',
						title: "请输入兑换次数次数"
					})
				} else {
					this.$api.change_num({
						num: this.value
					}, res => {
						// console.log(res);
						if (res.data.code == 1) {
							uni.showToast({
								icon: 'none',
								title: '兑换成功'
							})
							this.value = ''
							this.massage()
							setTimeout(()=>{
								uni.navigateBack()
							},1000)
						} else {
							uni.showToast({
								icon: 'none',
								title: res.data.msg
							})
						}
					})
				}

			}
		}
	}
</script>

<style scoped>
	page {
		/* 
		background: #F5F5F5FF !important; */
	}
</style>
